﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using MyIdolUIFrameWork;
using UnityEngine.SceneManagement;
using Beyond;

public class HomeController : BaseController
{

    public static HomeController instance;
    public Button removeAdBtn;
    public Image logo;
    protected override void Awake()
    {
        instance = this;
        base.Awake();
    }

    protected override void Start()
    {
        base.Start(); //CurrencyController.SetBalance(1);
        removeAdBtn.onClick.AddListener(OnRemoveAdsClick);
        ZJ_WangSir.CUtils.CloseBannerAd();
        if (ZJ_WangSir.CUtils.IsAdsRemoved())
            removeAdBtn.gameObject.SetActive(false);

        logo.SetNativeSize();
    }

    void Update()
    {
        if (GameState.judgeRemoveAd && ZJ_WangSir.CUtils.IsAdsRemoved())
        {
            removeAdBtn.gameObject.SetActive(false);
            GameState.judgeRemoveAd = false;
        }
        if (GetKeyDown.D())
        {
            PlayerPrefs.DeleteAll();
        }

        if (Input.GetKeyDown(KeyCode.Escape) && !DialogController.instance.IsDialogShowing())
        {
            if (SceneManager.GetActiveScene().name == "Home")
            {
#if UNITY_ANDROID
                if(NewInPromotions.Instance.mInpromotions_TC.active==true)
                {
                    NewInPromotions.Instance.mInpromotions_TC.SetActive(false);
                }
                else
                {
                    if (GameState.isPictureReady == false)
                    {
                        App.exit();
                    }
                    else
                    {
                        NewInPromotions.Instance.GetInPromotions_TC();
                    }
                }
#endif
            }
        }
    }

    public void OnPlayClick()
    {
        Sound.instance.PlayButton();
        int mode = Superpow.Utils.GetGameMode();
        CUtils.LoadScene(mode == 0 ? 2 : 1);
    }

    public void OnFacebookClick()
    {
        Sound.instance.PlayButton();
        CUtils.LikeFacebookPage(ConfigController.Config.facebookPageID);
    }

    public void OnRemoveAdsClick()
    {
        UIManager.Instance.SetVisible(UIName.UIRemoveAD, true);
    }

    public void UnlockAll()
    {
        for (int i = 0; i < 5; i++)
        {
            for (int a = 0; a < 16; a++)
            {
                LevelController.SetUnlockWorld(i);
                LevelController.SetUnlockLevel(i, a);
            }
        }
    }

    public void OpenWebBrowser()
    {
        App.openWebBrowser(AppInfo.getProperty("PAC_URL"));

    }
}
